package com.freak.wanandroid.model.myself.activity.collect;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.freak.httpmanager.BaseViewModel;
import com.freak.httpmanager.callback.ApiCallback;
import com.freak.httpmanager.callback.SubscriberCallBack;
import com.freak.wanandroid.bean.CollectBean;
import com.freak.wanandroid.net.CommonLiveData;

/**
 * Created by 74099 on 2018/8/29.
 */

public class CollectViewModel extends BaseViewModel<CollectRepository> {
    protected MutableLiveData<CollectBean> mGetCollectList = new MutableLiveData();
    protected MutableLiveData<String> mGetCollectListError = new MutableLiveData();
    protected MutableLiveData<CommonLiveData> mDoCancelCollect = new MutableLiveData<>();

    public CollectViewModel(@NonNull Application application) {
        super(application);
    }

    void getCollectList(String curPage) {
        mRepository.getCollectList(curPage, new SubscriberCallBack<>(new ApiCallback<CollectBean>() {
            @Override
            public void onSuccess(CollectBean model) {
                mGetCollectList.postValue(model);
            }

            @Override
            public void onFailure(String msg) {
                mGetCollectListError.postValue(msg);
            }
        }));
    }

    void doCollectCancel(int id, int originId) {
        mRepository.doCollectCancel(id, originId, new SubscriberCallBack<>(new ApiCallback<String>() {
            @Override
            public void onSuccess(String model) {
                mDoCancelCollect.postValue(new CommonLiveData(CommonLiveData.SUCCESS, model));
            }

            @Override
            public void onFailure(String msg) {
                mDoCancelCollect.postValue(new CommonLiveData(CommonLiveData.ERROR, msg));
            }
        }));
    }
}
